<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page session="false" %>
<%@ page isELIgnored ="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<script type="text/javascript">
//<![CDATA[
$kdom.appendDojoProp("btn_dd_new","label",$ksub(KppModule.commonResource.operCreate,[SysAdmin._resource.ddType]));
$kdom.appendDojoProp("btn_dd_refresh","label",KppModule.commonResource.refresh);
$kdom.appendDojoProp("btn_dd_newrootvalue","label",$ksub(KppModule.commonResource.operCreate,[SysAdmin._resource.dataDictRootValue]));
$kdom.appendDojoProp("menu_ddtype_edit","label",KppModule.commonResource.edit);
$kdom.appendDojoProp("menu_ddtype_delete","label",KppModule.commonResource.remove);
$kdom.appendDojoProp("treeContent","title",SysAdmin._resource.dataDictValue);
require(["dojo/store/Memory", "dijit/tree/ObjectStoreModel", "dijit/Tree"],
		function(Memory,ObjectStoreModel){
		
		if(typeof DataDict === "undefined" ){
			DataDict = {
				_dlgDdNewId:"dialog_config_datadict_new",
				_dlgDdEditId:"dialog_config_datadict_new",
				refreshType:function(){
					ddTypeGrid.setStore(DataDict.store);
				},
				callNewDdType:function(){
					 $ku.showDialog({
							id:"dialog_config_datadict_new",
							url:"../../config/dd/ddtype/new.html",
							title:$ksub(KppModule.commonResource.operCreate,[SysAdmin._resource.ddType]),
							resource:SysAdmin._resource,
							style:"width:300px;height:190px;"});
				},
				callEditDdType:function(did){
					 $ku.showDialog({
							id:"dialog_config_datadict_edit",
							url:"../../config/dd/ddtype/edit/"+did+".html",
							title:$ksub(KppModule.commonResource.operEdit,[SysAdmin._resource.ddType]),
							resource:SysAdmin._resource,
							style:"width:300px;height:190px;"});
				},
				remove:function(did){
					var options={
							domain:SysAdmin._resource.ddType,
							refresh:DataDict.refreshType,
							url:"../../config/dd/ddtype/"+did,
							button:dijit.byId("btn_ddType_del"),
							dialogId:"delTypeDlg",
							resource:SysAdmin._resource
					};
					KppModule.restProxy(options).remove();
				},
				callRemoveDdType:function(did){
					this.dlg=dijit.byId("delTypeDlg");
					if(!this.dlg)this.dlg=new dijit.Dialog({
							id:"delTypeDlg",
							title: KppModule.commonResource.confirm,
							style: "padding:0px;width:300px;height:200px;background-color:#FFF;"});
					this.dlg.set("content","<div style=\"padding:20px;text-align:center\">"+KppModule.commonResource.removeConfig+"</div>" +
							"<div style=\"text-align:center\"><div data-dojo-type=\"dijit.form.Button\" data-dojo-props=\"iconClass:'dijitEditorIcon dijitEditorIconDelete', id:'btn_ddType_del',showLabel:true, busyLabel:'"+KppModule.commonResource.removing+"'\">"+KppModule.commonResource.remove+
							"<script type=\"dojo/method\" event=\"onClick\" args=\"evt\">DataDict.remove('"+did+"',this)<\/script>"+
							"</div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+
							"<div data-dojo-type=\"dijit.form.Button\" data-dojo-props=\"iconClass:'dijitEditorIcon dijitEditorIconCancel', showLabel:true\">"+KppModule.commonResource.cancel +
							"<script type='dojo/method' event='onClick' args='evt'>dijit.byId('delTypeDlg').hide();<\/script></div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+
							"</div>"
						);
					this.dlg.show();
				},
				gridStructure:[
		       		{cells:[
						{field:"typeCode",name:SysAdmin._resource.ddTypeCode,formatter:$kt.escapeBlank,width:"200px",datatype:"string"},
						{field:"label",name:SysAdmin._resource.ddLabel,formatter:$kt.escapeBlank,width:"auto",datatype:"string"}
		       		]}
				],
				store:new dojox.data.QueryReadStore({url:'../../config/dd/ddtype/list.json'}),
				ddTypeId:"",
				ddValueTreeShow:function(did){
	    			 var xhrArgs = {
	 	    			    url: "../../config/dd/ddValue/list.json?typeId="+did,
	 	    			    handleAs: "text",
	 	    			    load: function(data){
	 	    			    	eval("data="+data);
	 	    			    	
	 	    			    	var store = new dojo.store.Memory({
							        data: data,
							        getChildren: function(object){
							            return this.query({parent: object.id});
							        }
								});
	 	    			    	
	 	    			    	myModel = new dijit.tree.ObjectStoreModel({
	 	    			           store: store,
	 	    			           query: {id: 'root'}
	 	    			       });
	 	    			    	
	 	    			    	tree=dijit.byId("ddValueTree");
	 	    			    	if(tree!=null){
	 	    			    		tree.destroy();
	 	    			    		dojo.byId("treeContent").innerHTML='<div id="ddValueTree"></div>';
	 	    			    	}
										 	    			    	
	 	    			    	menuTree = new dijit.Tree({
	 	    			    		model : myModel,
	 	    			    		showRoot: false,
	 	    			    		openOnClick: false
	 	    			    	}, 'ddValueTree');
	 	    			    	
	 	    			    	menuTree.startup();
	 	    			    	
	 	    			    	var pMenu;
	 	    			        pMenu = new dijit.Menu({
	 	    			            targetNodeIds: ["ddValueTree"],
	 	    			           	selector: ".dijitTreeNode",
	 	    			           	style:"display: none;"
	 	    			        });
	 	    			        pMenu.addChild(new dijit.MenuItem({
	 	    			            label:$ksub(KppModule.commonResource.operCreate,[SysAdmin._resource.dataDictValue]) ,
	 	    			            iconClass: "icon_s_office icon_s_office_table_new",
	 	    			            onClick: function(){
	 	    			            	var tn = dijit.byNode(this.getParent().currentTarget);
	 									var dvId=tn.item.id;
	 									$ku.showDialog({
	 										id:"dialog_config_datadictvalue_new",
	 										url:"../../config/dd/ddvalue/"+dvId+"/new.html?typeId="+DataDict.ddTypeId,
	 										title:$ksub(KppModule.commonResource.operCreate,[SysAdmin._resource.dataDictValue]),
	 										resource:SysAdmin._resource,
	 										style:"width:300px;height:190px;"});
	 	    			            }
	 	    			        }));
	 	    			       pMenu.addChild(new dijit.MenuItem({
	 	    			            label:$ksub(KppModule.commonResource.operEdit,[SysAdmin._resource.dataDictValue]) ,
	 	    			            iconClass: "icon_s_office icon_s_office_table_edit",
	 	    			            onClick: function(){
	 	    			            	var tn = dijit.byNode(this.getParent().currentTarget);
	 									var dvId=tn.item.id;
	 									if(dvId!="root"){
		 									$ku.showDialog({
		 										id:"dialog_config_datadictvalue_edit",
		 										url:"../../config/dd/ddvalue/edit/"+dvId+".html",
		 										title:$ksub(KppModule.commonResource.operEdit,[SysAdmin._resource.dataDictValue]),
		 										resource:SysAdmin._resourse,
		 										style:"width:300px;height:190px;"});
		 									}
	 	    			            }
	 	    			        }));
	 	    			      pMenu.addChild(new dijit.MenuItem({
	 	    			            label:$ksub(KppModule.commonResource.operDelete,[SysAdmin._resource.dataDictValue]),
	 	    			            iconClass: "icon_s_office icon_s_office_table_remove",
	 	    			            onClick: function(){
	 	    			            	var tn = dijit.byNode(this.getParent().currentTarget);
	 	                           		var dvId=tn.item.id;
	 									if(dvId!="root"){

	 									this.dlg=dijit.byId("delValueDlg");
	 									if(!this.dlg)this.dlg=new dijit.Dialog({
	 										id:"delValueDlg",
	 										title: KppModule.commonResource.confirm,
	 										style: "padding:0px;width:300px;height:200px;background-color:#FFF;"});
	 										this.dlg.set("content","<div style=\"padding:20px;text-align:center\">"+KppModule.commonResource.removeValueConfig+"</div>" +
	 										"<div style=\"text-align:center\"><div data-dojo-type=\"dijit.form.Button\" data-dojo-props=\"iconClass:'dijitEditorIcon dijitEditorIconDelete', id:'btn_ddvalue_del',showLabel:true, busyLabel:'"+KppModule.commonResource.removing+"'\">"+KppModule.commonResource.remove+
	 										"<script type=\"dojo/method\" event=\"onClick\" args=\"evt\">DataDict.ddValueRemove('"+dvId+"',this)<\/script>"+
	 										"</div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+
	 										"<div data-dojo-type=\"dijit.form.Button\" data-dojo-props=\"iconClass:'dijitEditorIcon dijitEditorIconCancel', showLabel:true\">"+KppModule.commonResource.cancel +
	 										"<script type='dojo/method' event='onClick' args='evt'>dijit.byId('delValueDlg').hide();<\/script></div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+
	 										"</div>"
	 									);
	 									this.dlg.show();
	 									}
	 	    			            }
	 	    			        }));
	 	    			    dojo.query(".dijitTreeIcon").removeClass("dijitFolderOpened").addClass("icon_s_office icon_s_office_table");
	 	    			    },
	 	    			    error: function(error){
	 	    			    }
	 	    			  };
	 	    		dojo.xhrGet(xhrArgs);
	    		 },
	    		 ddValueTreeRefresh:function(){
	    			 DataDict.ddValueTreeShow(DataDict.ddTypeId);
	    		 },
	    		 ddValueRemove:function(did){
	    			 var options={
								domain:SysAdmin._resource.dataDictValue,
								refresh:DataDict.ddValueTreeRefresh,
								url:"../../config/dd/ddvalue/"+did,
								button:dijit.byId("btn_ddvalue_del"),
								dialogId:"delValueDlg",
								resource:SysAdmin._resource
						};
						KppModule.restProxy(options).remove();
	    		 },
	    		 ddValueNewRoot:function(){
	    			 if(DataDict.ddTypeId!=null&&DataDict.ddTypeId!=""){
	    				 $ku.showDialog({
								id:"dialog_config_datadictvalue_new",
								url:"../../config/dd/ddRootvalue/new.html?typeId="+DataDict.ddTypeId,
								title:$ksub(KppModule.commonResource.operCreate,[SysAdmin._resource.dataDictValue]),
								resource:SysAdmin._resource,
								style:"width:300px;height:190px;"});
	    			 }else{
	    				 alert("请先选择一个字典再增加新的根数据项");
	    			 }
	    		 }
			};
		};
		$kdom.appendDojoProp("cp_dd_nav","content","<img class=\"icon_s_admin icon_s_admin_module_double\" src=\"${pageContext.request.contextPath}/assets/images/blank.gif\" /><span>"+SysAdmin._resource.dataDict+"</span>");
});
//]]>
</script>

<span style="display:none">To solve IE7/8 script event tag problem.</span>
<div data-dojo-type="dijit/layout/BorderContainer" data-dojo-props="liveSplitters:true" class="contentWrapper" style="margin:-2px;height:100%">
	<div id="cp_dd_nav" data-dojo-type="dijit/layout/ContentPane"  data-dojo-props="region:'top'" class="contentWrapperRight contentPaneNav" style="border:none;margin:-4px;padding:10px 0 10px 10px;background-color:transparent">
	</div>
	<div data-dojo-type="dijit/layout/BorderContainer" data-dojo-props="region:'left'" style="width:450px;margin: -9px 0px;">
		<div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region:'top'"  style="border:none;background-color:transparent;">
			<div data-dojo-type="dijit/form/Button" id="btn_dd_new" data-dojo-props="iconClass:'icon_s_admin icon_s_admin_module_new'"
				onclick="DataDict.callNewDdType()" >
			</div>
			<div data-dojo-type="dijit/form/Button" id="btn_dd_refresh" data-dojo-props="iconClass:'dijitCommonIcons dijitIconUndo'"
				onclick="DataDict.refreshType()" >
			</div>
		</div>
		<div data-dojo-type="dojox/grid/EnhancedGrid" id="ddTypeGrid" class="nihilo kpp" data-dojo-id="ddTypeGrid"
			data-dojo-props="plugins:{menus:{selectedRegionMenu:'selectedRegionMenu'}},structure:DataDict.gridStructure,store:DataDict.store,canSort:function(){return false;},style:'margin:-9px 7px 7px;height:100px',region:'center',store:DataDict.store,canSort:function(){return false;},rowsPerPage:20" >
			<script type="dojo/on" data-dojo-event="selected" data-dojo-args="evt">
				var table=dijit.byId("ddTypeGrid");
				var index=evt;
				var row=table.getItem(index);
				DataDict.ddTypeId=row.i.id;
				DataDict.ddValueTreeShow(row.i.id);
				dijit.byId("treeContent").set("title",SysAdmin._resource.dataDictValue+" &raquo; "+row.i.label);
			</script>
			<div data-dojo-type="dijit/Menu" id="selectedRegionMenu" style="display: none;">
	        	<div data-dojo-type="dijit/MenuItem" id="menu_ddtype_edit" data-dojo-props="iconClass:'icon_s_admin icon_s_admin_module_edit'">edit
	        		<script type="dojo/on" data-dojo-event="click" data-dojo-args="evt">
						DataDict.callEditDdType(DataDict.ddTypeId);
					</script>
	        	</div>
	        	<div data-dojo-type="dijit/MenuItem" id="menu_ddtype_delete" data-dojo-props="iconClass:'icon_s_admin icon_s_admin_module_remove'">delete
	        		<script type="dojo/on" data-dojo-event="click" data-dojo-args="evt">
						DataDict.callRemoveDdType(DataDict.ddTypeId);
					</script>
	        	</div>
	    	</div>
	</div>
	</div>
	<div data-dojo-type="dijit/layout/BorderContainer" data-dojo-props="region:'center'" style="margin:-9px 0px;height:100%">
		<div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region:'top'"  style="border:none;background-color:transparent;">
			<div data-dojo-type="dijit/form/Button" id="btn_dd_newrootvalue" data-dojo-props="iconClass:'icon_s_office icon_s_office_table_new'"
			onclick="DataDict.ddValueNewRoot()" ></div>
		</div>
		<div data-dojo-type="dijit/layout/AccordionContainer" data-dojo-props="region:'center'" style="margin:-9px 0px 6px;height:100%">
			<div id="treeContent" data-dojo-type="dijit.layout.ContentPane" data-dojo-props="">
				<div id="ddValueTree"></div>
			</div>
		</div>
	</div>
</div>